﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefMeterDataRecord" :model="stateMeterDataRecord.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DeviceId_FormItem" prop="Entity.DeviceId" :label="$t('message.autotrans._Model_MeterDataRecord_Device')">
            <el-select v-model="stateMeterDataRecord.vmModel.Entity.DeviceId" clearable>
               <el-option v-for="item in stateMeterDataRecord.AllDevices" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Source_FormItem" prop="Entity.Source" :label="$t('message.autotrans._Model_MeterDataRecord_Source')">
            <el-select v-model="stateMeterDataRecord.vmModel.Entity.Source" clearable>
               <el-option key="AutoCollect" value="AutoCollect" :label="$t('message.autotrans._Enum_DataSourceEnum_AutoCollect')"></el-option>
               <el-option key="ManualInput" value="ManualInput" :label="$t('message.autotrans._Enum_DataSourceEnum_ManualInput')"></el-option>
               <el-option key="Import" value="Import" :label="$t('message.autotrans._Enum_DataSourceEnum_Import')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CollectStatus_FormItem" prop="Entity.CollectStatus" :label="$t('message.autotrans._Model_MeterDataRecord_CollectStatus')">
            <el-select v-model="stateMeterDataRecord.vmModel.Entity.CollectStatus" clearable>
               <el-option key="Success" value="Success" :label="$t('message.autotrans._Enum_CollectStatusEnum_Success')"></el-option>
               <el-option key="Failed" value="Failed" :label="$t('message.autotrans._Enum_CollectStatusEnum_Failed')"></el-option>
               <el-option key="Timeout" value="Timeout" :label="$t('message.autotrans._Enum_CollectStatusEnum_Timeout')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IsAbnormal_FormItem" prop="Entity.IsAbnormal" :label="$t('message.autotrans._Model_MeterDataRecord_IsAbnormal')">
            <el-select v-model="stateMeterDataRecord.vmModel.Entity.IsAbnormal" clearable>
               <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
               <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_AbnormalReason_FormItem" prop="Entity.AbnormalReason" :label="$t('message.autotrans._Model_MeterDataRecord_AbnormalReason')">
            <el-input v-model="stateMeterDataRecord.vmModel.Entity.AbnormalReason" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CurrentValue_FormItem" prop="Entity.CurrentValue" :label="$t('message.autotrans._Model_MeterDataRecord_CurrentValue')">
            <el-input v-model="stateMeterDataRecord.vmModel.Entity.CurrentValue" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ParameterId_FormItem" prop="Entity.ParameterId" :label="$t('message.autotrans._Model_MeterDataRecord_Parameter')">
            <el-select v-model="stateMeterDataRecord.vmModel.Entity.ParameterId" clearable>
               <el-option v-for="item in stateMeterDataRecord.AllParameters" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ParameterName_FormItem" prop="Entity.ParameterName" :label="$t('message.autotrans._Model_MeterDataRecord_ParameterName')">
            <el-input v-model="stateMeterDataRecord.vmModel.Entity.ParameterName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DataValueType_FormItem" prop="Entity.DataValueType" :label="$t('message.autotrans._Model_MeterDataRecord_DataValueType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDataRecord_DataValueType')}), trigger: 'blur' }]" >
            <el-select v-model="stateMeterDataRecord.vmModel.Entity.DataValueType" clearable>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Usage_FormItem" prop="Entity.Usage" :label="$t('message.autotrans._Model_MeterDataRecord_Usage')">
            <el-input v-model="stateMeterDataRecord.vmModel.Entity.Usage" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Unit_FormItem" prop="Entity.Unit" :label="$t('message.autotrans._Model_MeterDataRecord_Unit')">
            <el-input v-model="stateMeterDataRecord.vmModel.Entity.Unit" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ReadingTime_FormItem" prop="Entity.ReadingTime" :label="$t('message.autotrans._Model_MeterDataRecord_ReadingTime')">
            <el-date-picker v-model="stateMeterDataRecord.vmModel.Entity.ReadingTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitMeterDataRecord"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseMeterDataRecord"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageIoTManagementMeterDataRecordCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { meterdatarecordApi } from '/@/api/iotmanagement/meterdatarecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMeterDataRecord = ref();
const stateMeterDataRecord = reactive({
    vmModel: {
	  Entity:{
        DeviceId: null,
        Source: undefined,
        CollectStatus: undefined,
        IsAbnormal: undefined,
        AbnormalReason: '',
        CurrentValue: null,
        ParameterId: null,
        ParameterName: '',
        DataValueType: undefined,
        Usage: null,
        Unit: '',
        ReadingTime: undefined,
      },

	},
    
    AllDevices: [] as any[],
    AllParameters: [] as any[],
});

// 取消
const onCloseMeterDataRecord = () => {
    closeDialog();
};

// 提交
const onSubmitMeterDataRecord = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefMeterDataRecord.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            meterdatarecordApi().add(stateMeterDataRecord.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/IoTManagement/MeterDataRecord/GetMeterDevices',[],false).then(x=>{stateMeterDataRecord.AllDevices = x});
    other.getSelectList('/api/IoTManagement/MeterDataRecord/GetMeterParameters',[],false).then(x=>{stateMeterDataRecord.AllParameters = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

